package com.yizhubao.app.customviews;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.yizhubao.app.R;

import h.framework.pacy.utils.StringUtil;

/**
 * 创建人: PACY
 * 创建时间: 6/9/21 9:50 AM
 * 邮箱: pengwwe457621023@qq.com
 * 类描述: 支付页面第一排自定义View
 */
public class PayItem1View extends LinearLayout {
    String title;
    int icon;

    ImageView iconIv;
    TextView titleTv;

    public PayItem1View(Context context) {
        super(context);
    }

    public PayItem1View(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        /**
         * 加载布局  获取自定义属性
         */
        LayoutInflater.from(context).inflate(R.layout.pay_item1, this, true);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PayItem1View);
        title = a.getString(R.styleable.PayItem1View_pi1Title);
        icon = a.getResourceId(R.styleable.PayItem1View_pi1Icon, R.drawable.zhifu_icon_xiugai);
        a.recycle();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        iconIv=findViewById(R.id.icon);
        titleTv=findViewById(R.id.title);


        if(StringUtil.isNotEmpty(title)){
            setTitleTv(title);
            setIcon(icon);
        }else{
            throw new NullPointerException("title is not empty");
        }
    }

    /**
     * 设置图标
     *
     * @param iconResource
     */
    public void setIcon(int iconResource) {
        iconIv.setBackgroundResource(iconResource);
    }

    /**
     * 设置标题
     * @param title
     */
    public void setTitleTv(String title){
        titleTv.setText(title);
    }
}
